#include<iostream>
using namespace std;
class CStack
{
    private:
        int* array;
        int size;
        int top;
    public:
        CStack(int s=10)
        {
            size=s;
            array=new int[s];
            if(s!=0)
                top=0;
            cout<<"Constructor."<<endl;
        }
        int get(int index)
        {
            return array[index];
        }
        void push(int n)
        {
            array[top]=n;
            ++top;
        }
        int IsEmpty()
        {
            if(top==0)
                return true;
            else
                return false;
        }
        int IsFull()
        {
            if(top==size)
                return true;
            return false;
        }
        int pop()
        {
            int num=array[--top];
            return num;
        }
        ~CStack()
        {
            delete[] array;
            cout<<"Destructor."<<endl;
        }

};
int main()
{
    int time;
    cin>>time;
    while(time--)
    {
        int size;
        cin>>size;
        CStack tmp(size);
        for(int i=0;i<size;i++)
        {
            int num;
            cin>>num;
            tmp.push(num);
        }
        cout<<tmp.pop();
        for(int i=1;i<size;i++)
        {
            cout<<" "<<tmp.pop();
        }
        cout<<endl;
    }
}